package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.ReportMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.ReportService;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ReportServiceImpl  implements ReportService {

//    @Reference
//    private MemberService memberService;

    @Autowired
    private  ReportMapper reportMapper;


    @Override
    public Map findLastyearMemberCountsByMonth() {
        List<Map> mapList = reportMapper.findLastyearMemberCountsByMonth();
        Map map = changeData(mapList);
        return map;
    }

    @Override
    public List<Map> getSetmealProportion() {
        return reportMapper.getSetmealProportion();
    }

    private Map changeData(List<Map> mapList) {
         List<String> yearAndMonthList = new ArrayList<String>();
         List<Long> memberCountList = new ArrayList<Long>();
        Map map = new HashMap();
        for (Map map1 : mapList) {
            yearAndMonthList.add((String)map1.get("yearAndMonth"));
            memberCountList.add((Long)map1.get("memberCounts"));
        }
        map.put("memberCounts",memberCountList);
        map.put("yearAndMonth",yearAndMonthList);
        return map;
    }
}
